import { handleExportError, messages } from "share/common";
import Importer from "components/template/importer";
import React from "react";
import ExportModal from "components/template/export-modal/export-modal";

const legalPersonTemplates = [
  {
    downloadName: messages("basic-5.key227") /*法人信息导入模板*/,
    templateName: messages("basic-5.key227") /*法人信息导入模板*/,
    downloadUrl: "/api/common/upload/template/LEGAL_ENTITY",
  },
  {
    downloadName: "bank_info",
    templateName: messages("basic-5.key228") /*银行基础数据*/,
    downloadUrl: "http://helioscloud-uat-static.oss-cn-shanghai.aliyuncs.com/bank_info.xlsx",
    templateTips: messages("basic-5.key229") /*银行基础数据（录入银行信息时请根据银行数据录入，该文件无须上传）*/,
  },
];

const companyTemplates = [
  {
    downloadName: messages("basic-5.key183") /*公司信息导入模板*/,
    templateName: messages("basic-5.key183") /*公司信息导入模板*/,
    downloadUrl: "/api/common/upload/template/COMPANY",
  },
  {
    downloadName: "helios_city",
    templateName: messages("basic-5.key184") /*城市基本信息表*/,
    downloadUrl: "http://cloudhelios-static.oss-cn-shanghai.aliyuncs.com/other/helios_city.xlsx",
    templateTips: messages("basic-5.key185") /*下载《城市基本信息表》，导入城市的编码需与表中的编码一致*/,
  },
];

export default {
  importHandler(btn, context) {
    let result;
    switch (btn.key) {
      case "import-legal-person":
        result = (
          <Importer
            triggerNode={<span>{btn.name}</span>}
            btnName={messages("basic-5.key237") /*导入法人实体*/}
            modalOptions={{ title: messages("basic-5.key237") /*导入法人实体*/ }}
            onOk={() => {
              context.handleAfterClose("legalEntity");
            }}
            templateOptions={{ templateList: legalPersonTemplates }}
            uploadOptions={{
              uploadUrl: `/api/common/upload?importType=LEGAL_ENTITY`,
              listenUrl: "/api/batch/transaction/logs/v2",
            }}
            uploadResultOptions={{
              shouldDownloadErrorInfo: true,
              showErrorTable: true,
              queryMode: true,
              errorUrl: "/api/common/upload/error/export",
              getErrorTableVisible: (result) => result && result.failureEntities > 0,
            }}
            totalError={(data) => {
              return data && data.failureEntities;
            }}
            errorTableData={(data) => handleExportError(data)}
          />
        );
        break;
      case "import-company":
        result = (
          <Importer
            triggerNode={<span>{btn.name}</span>}
            onOk={() => {
              context.handleAfterClose("company");
            }}
            templateOptions={{ templateList: companyTemplates }}
            uploadOptions={{
              uploadUrl: `/api/common/upload?importType=COMPANY`,
              listenUrl: "/api/batch/transaction/logs/v2",
              // disabled,
            }}
            uploadResultOptions={{
              shouldDownloadErrorInfo: true,
              showErrorTable: true,
              queryMode: true,
              errorUrl: "/api/common/upload/error/export",
              getErrorTableVisible: (result) => result && result.failureEntities > 0,
            }}
            totalError={(data) => {
              return data && data.failureEntities;
            }}
            errorTableData={(data) => handleExportError(data)}
          />
        );
        break;
      case "default":
        result = btn.name;
        break;
    }
    return result;
  },
  exportHandler(btn) {
    let result;
    switch (btn.key) {
      case "export-legal-entity":
        result = (
          <ExportModal
            triggerNode={<span>{btn.name}</span>}
            codeCheck
            type={"btn"}
            exportTitle={messages("basic-5.key232") /*导出法人实体*/}
            exportType="LEGAL_ENTITY"
            // exportCondition={{
            //   keyword: params.keyword,
            //   querySetOfbooksId: params.setOfBooksId,
            // }}
            exportCommand={"legal_entity"}
          />
        );
        break;
      case "export-company-info":
        result = (
          <ExportModal
            triggerNode={<span>{btn.name}</span>}
            exportTitle={messages("basic-5.key187") /*公司信息数据*/}
            exportType={"COMPANY"}
            // exportCondition={exportCondition}
            exportCommand={"company"}
          />
        );
        break;
      case "export-company-bank-info":
        result = (
          <ExportModal
            triggerNode={<span>{btn.name}</span>}
            exportTitle={messages("basic-5.key188") /*银行信息数据*/}
            exportType={"COMPANY"}
            // exportCondition={exportCondition}
            exportCommand={"company_bank"}
          />
        );
        break;
      case "default":
        result = btn.name;
        break;
    }
    return result;
  },
};
